﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace PMS.DAL
{
    public sealed class ServiceFactory<T> where T : class
    {
        private T currentDAL;
        public T CurrentDAL
        {
            get
            {
                if (this.currentDAL == null)
                    this.currentDAL = this.GetDAL();
                return currentDAL;
            }
        }

        private T GetDAL()
        {
            var k = Assembly.GetAssembly(this.GetType()).GetTypes().Where(t => t.GetInterface(typeof(T).Name) != null).FirstOrDefault();

            if (k != null)
                return (T)Activator.CreateInstance(k);
            return default(T);
        }
    }
}
